findMdpCode.js ➔ findMdpCode   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 4
c 2
b 0
f 0
nc 2
nop 2
dl 0
loc 13
rs 9.2
1
/** findMdpInsert and findCode functions use a similar layout to return the location and contents
2
  *   .start          => points at the character in the string why the other item starts (ie. comment or code block)
3
  *   .length         => is the overall length of the comment or code block.
4
  *   .internalStart  => points at the character in the string where the internal payload starts
5
  *   .internalLength => is the length of the internal payload
6
  *   .commandString  => is the command string found within the particular item
7
  *   .info           => is a structure containing further info about what was found
8
  * if start is returned as -1 then nothing was found
9
  *
10
  * The internalStart/internaLength defines the internal content which will be replaced. This does not include
11
  * leading and lagging CRLF/LF. So the replacement text is not required to have either leading or lagging line
12
  * endings. However, if the internalLength is negative this means that leading CRLF or LF must be added by the insertion
13
  * routine. The reason for this is that it allows insertions between code fences or mdpInsert pairs which have zero lines
14
  * between them.
15
  *
16
**/
17
18
const {findCode} = require('./findCode.js')
19
20
export function findMdpCode (txt, start) {
21
  // finds the next location of mdpInsert in a code span within txt
22
  let posn = start
23
  let x
24
  do {
25
    x = findCode(txt, posn)
26
    if (x.start === -1 || x.commandString.indexOf('mdpInsert ') !== -1) {
27
      break
28
    }
29
    posn = x.start + x.length
30
  } while (true)
31
  return x
32
}
33